﻿using AmiCheckin.UI.ViewModels;
using System.Windows;
using System.Windows.Controls;

namespace AmiCheckin.UI.Views
{
    public partial class CheckinSetView : UserControl
    {
        public CheckinSetView()
        {
            InitializeComponent();
        }

        private void Button_AddSet(object sender, System.Windows.RoutedEventArgs e)
        {

                ViewModel.CheckinSetObjects.Add(new() { Name = "新增设置" });
            
        }

        private void Button_RemoveSet(object sender, RoutedEventArgs e)
        {
            if (ListBox.SelectedIndex != -1)
                ViewModel.CheckinSetObjects.RemoveAt(ListBox.SelectedIndex);
        }

        private void Button_Save(object sender, System.Windows.RoutedEventArgs e)
        {
            this.ViewModel.Save();
            MessageBox.Show("保存成功~请手动重载config.json");
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.ViewModel.Load();
        }

        private void Button_AddGroup(object sender, RoutedEventArgs e)
        {
            if (InputDialog.GetInput(out var input))
            {
                (ListBox.SelectedItem as ObservableCheckinSet)?.SpecialGroups.Add(long.Parse(input));
            }
        }

        private void Button_DelGroup(object sender, RoutedEventArgs e)
        {

            if (GroupListBox.SelectedIndex != -1)
                (ListBox.SelectedItem as ObservableCheckinSet)?.SpecialGroups.RemoveAt(GroupListBox.SelectedIndex);

        }

        private void Button_AddReward(object sender, RoutedEventArgs e)
        {
            if (InputDialog.GetInput(out var input))
            {
                (ListBox.SelectedItem as ObservableCheckinSet)?.SpecialGroups.Add(long.Parse(input));
            }
        }

        private void Button_DelReward(object sender, RoutedEventArgs e)
        {
            throw new System.NotImplementedException();
        }
    }
}